/*
 * @LastEditTime: 2023-03-18 12:09:05
 * @Method: 
 * @Description: 
 */
package Preview.meituan;

import java.util.HashMap;
import java.util.Scanner;

public class Main2 {
    public static int fun (int N, int K, int[] nums) {
        HashMap<Integer, Integer> colorMap = new HashMap<>();
        int maxLen = 0, len = 0;
        for (int i = 0;i < N;i++) {
            colorMap.put(nums[i], colorMap.getOrDefault(nums[i], 0) + 1);
            len++;
            while (colorMap.size() > K && len > 0) {
                colorMap.put(nums[i - len + 1], colorMap.getOrDefault(nums[i - len + 1], 0) - 1);
                if (colorMap.get(nums[i - len + 1]) == 0) {
                    colorMap.remove(nums[i - len + 1]);
                }
                len--;
            }
            maxLen = Math.max(len, maxLen);
        }
        return maxLen;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] nums = new int[N];
        for (int i = 0;i < nums.length;i++) {
            nums[i] = sc.nextInt();
        }
        System.out.println(fun(N, K, nums));
    }
}
